package reflection;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Properties;

public class ReflectionQuestion {
    public static void main(String[] args) throws Exception {
        Properties properties = new Properties();
        properties.load(new FileReader("src/re.properties"));
        String classfullpath = properties.getProperty("classfullpath");
        String method = properties.getProperty("method");
        System.out.println(classfullpath+method);

        Class<?> aClass = Class.forName(classfullpath);
        Object o = aClass.newInstance();//获取对象
        Method method1 = aClass.getMethod(method);
        Object invoke = method1.invoke(o);//获取方法
        System.out.println(invoke);

        Field name = aClass.getField("name");//获取属性 这样无法获取私有属性
        System.out.println(name.get(o));

        Constructor<?> constructor = aClass.getConstructor();//获取无参数构造器
        System.out.println(constructor);
        Constructor<?> constructor1 = aClass.getConstructor(String.class);//获取String类型有参构造器
        System.out.println(constructor1);
    }

}
